const redis = require('redis');
const http = require("http");

//本机端口
const PORT = '9012';

//所有服务的域名ip
const httpJson = {
    activitiServerHttp: 'http://192.168.20.19:9011',
};

/**
 * 调用其他服务ajax封装
 * opt = {
        host: 'localhost',
        port: COM_CONFIG.port,
        method: 'GET',
        path: '/swagger.json'
    }
 * @param {*} opt 
 */
let post = async (json) => {
    try {
        return await new Promise((r, j) => {
            let opt = json.opt ? json.opt : { method: 'POST' };
            let req = http.request(json.url, opt, function (res) {
                res.setEncoding('utf-8');
                res.on('data', function (data) {
                    return r(data);
                });
                res.on('error', function (e) {
                    console.log("请求其他服务失败:", e);
                    return r(false);
                });
            });
            req.on('error', function (e) {
                console.log("请求其他服务失败:", e);
                return r(false);
            })
            if (json.data) {
                req.write(json.data);
            }
            req.end();
        });
    } catch (e) { console.log(e); return false; }
};


module.exports = {
    //本机端口
    port: PORT,
    //mongo地址
    dbAddress: "mongodb://admin:amkj_mongo@ip.nejery.com:7009/",
    //mongo数据过期时间 - 10天    
    mongoExpires: 10 * 24 * 60 * 60,
    //学生人物关系数据过期时间(过期了会重新拉取生成，目的是更新学生家长信息) - 3个月
    studentRelationExpires: 3 * 30 * 24 * 60 * 60,
    //保安位置信息过期时间 - 5天
    securityPointExpires: 5 * 24 * 60 * 60,
    //sos报警保安距离学生多远算保安抵达报警点 单位 m
    securityArrival: 300,
    //时间差为多久算在线 - 单位s
    onLineDis: 15 * 60,
    //查询学生轨迹的默认几天（3）前 单位 ms
    stuOrbitS: 259200000,
    //日志收集IP
    logstashHost: 'ip.nejery.com',
    //日志收集端口
    logstashPort: '7010',
    //rabbit配置
    rabbitmq: {
        host: '192.168.20.19',
        port: '5672',
        user: 'admin',
        password: 'admin',
        //学生位置队列
        queue: 'student-location',
        //存出行记录队列
        travelRecordQueue: 'access-record-info',
        //保安位置队列
        securityPointInfo: 'security-point-info',
        //日志队列
        quLogs: 'school-system-logs',
        //node和activiti通信队列 - 暂时没用
        nodeActivit: 'node-activit'
    },
    //activiti服务url
    activitiService: {
        //sos校徽报警
        sosAlarm: httpJson.activitiServerHttp + '/alarm/sosAlarm',
        //得到某个组织所有的人员信息
        getAllRoleInfo: httpJson.activitiServerHttp + '/user/getRolesUser',
        //保安抵达报警点
        securityArrival: httpJson.activitiServerHttp + '/sos/securityArrival',
        //电子围栏报警
        fenceSos: httpJson.activitiServerHttp + '/sos/fenceSos'
    },
    //请求其他服务
    post: post,
    //redis连接
    redis: redis.createClient({
        host: '192.168.20.18',
        port: 6379,
        password: '123456',
        db: 3
    })
}
